var templateParams = {
    tableTheads:["节点名称", "IP", "用户名", "最大线程","当前执行线程", "状态", "工作目录", "创建时间", "创建人", "备注","操作"],
    btnTools:[{
        type:"danger",
        size:"M",
        id:"batch-op",
        iconFont:"&#xe6bf;",
        name:"批量操作"
    }],
    formControls:[{
        edit:true,
        label:"ID",
        objText:"idText",
        input:[{
            hidden:true,
            name:"id"
        }]
        },
        {
            required:true,
            label:"节点名称",
            input:[{
                name:"slave_name"
            }]
        },
        {
            label:"IP",
            objText:"ipText",
            input:[{
                name:"ip",
                hidden: true
            }]
        },
        {
            label:"用户名",
            objText:"user_nameText",
            input:[{
                name:"username",
                hidden: true
            }]
        },
        {
            required:true,
            label:"最大执行线程",
            input:[{
                name:"parallel_max"
            }]
        },
        {
            required:true,
            label:"当前执行执行线程",
            input:[{
                name:"parallel_now"
            }]
        },
        {
            label:"状态",
            objText: "statusText",
            input:[{
                name:"status",
                hidden: true
            }]
        },
        {
            required: true,
            label:"工作目录",
            input:[{
                name:"work_path"
            }]
        },
        {
            label:"备注",
            textarea:[{
                name:"mark"
            }]
        }
    ]};

var columnsSetting = [
    {
        "data":null,
        "render":function(data, type, full, meta){
            return checkboxHmtl(data.slave_name, data.id, "selectSlave");
        }},
    ellipsisData("slave_name"),
    ellipsisData("ip"),
    ellipsisData("username"),
    {"data": "parallel_max"},
    {"data": "parallel_now"},
    {"data": "status"},
    ellipsisData("work_path"),
    ellipsisData("create_time"),
    ellipsisData("creator_name"),
    longTextData("mark", "slave_name", "备注信息"),
    {
        "data":null,
        "render":function(data, type, full, meta){
            var context = [];
            if (data.if_accept == '0') {
                context.push({
                    title:"添加管理",
                    markClass:"add-manager",
                    iconFont:"&#xe600;"
                });
            } else {
                context.push(
                    {
                        title:"编辑",
                        markClass:"object-edit",
                        iconFont:"&#xe6df;"
                    }, {
                        title:"删除管理",
                        markClass:"del-manager",
                        iconFont:"&#xe6e2;"
                    }, {
                        title:"断开连接",
                        markClass:"disconnet",
                        iconFont:"&#xe726;"
                    });
            }
            return btnIconTemplate(context);
        }
    }];

var eventList = {
    "#batch-op":function(){
        layer.confirm(
            '请选择你需要进行的批量操作:',
            {
                title:'批量操作',
                btn:['取消管理', '添加管理', '关闭'],
                shadeClose:true,
                btn3: function(index){
                    layer.close(index);
                }
            },function(index){
                layer.close(index);
                batchOp($(".selectSlave:checked"), REQUEST_URL.WEB_EXECUTION_MACHINE.delManagerMachine, "取消管理", null, "id");
            },function(index){
                layer.close(index);
                batchOp($(".selectSlave:checked"), REQUEST_URL.WEB_EXECUTION_MACHINE.addManagerMachine, "添加管理", null, "id");
            });
    },
    ".object-edit":function(){
        var data = table.row( $(this).parents('tr') ).data();
        publish.renderParams.editPage.modeFlag = 1;
        publish.renderParams.editPage.objId = data.id;
        publish.renderParams.editPage.currentObj = data;
        layer_show("编辑执行机信息", editHtml, editPageWidth, editPageHeight.edit, 1);
        publish.init();
    },
    ".del-manager":function(){
        let data = table.row( $(this).parents('tr') ).data();
        opObj("确认要取消对该执行机的管理吗？", REQUEST_URL.WEB_EXECUTION_MACHINE.delManagerMachine, {id:data.id}, null, "取消管理成功!", function(){
            refreshTable();
        });
    },
    ".add-manager":function(){
        let data = table.row( $(this).parents('tr') ).data();
        opObj("确认要添加对该执行机的管理吗？", REQUEST_URL.WEB_EXECUTION_MACHINE.addManagerMachine, {id:data.id}, null, "添加管理成功!", function(){
            refreshTable();
        });
    },
    ".disconnet": function(){
        let data = table.row( $(this).parents('tr') ).data();
        layer.confirm('确认断开该执行机的连接吗？', {title: '警告', icon: 0}, function(index){
            GLOBAL_UTILS.ajaxUtils.ajaxGet(REQUEST_URL.WEB_EXECUTION_MACHINE.breakSlave + "&slaveId=" + data.id, function(d){
                layer.msg('已断开!', {icon: 1, time: 1400});
                refreshTable();
            }, null, null, null, "正在断开连接...");
            layer.close(index);
        });
    }

};

var groupId;
var mySetting = {
    eventList:eventList,
    templateCallBack:function(df){
        groupId = GetQueryString("group_id");
        publish.renderParams.listPage.listUrl = REQUEST_URL.WEB_EXECUTION_MACHINE.listMachine + "&group_id=" + groupId;

        df.resolve();
    },
    listPage:{
        listUrl:REQUEST_URL.WEB_EXECUTION_MACHINE.listMachine,
        tableObj:".table-sort",
        columnsSetting:columnsSetting,
        columnsJson:[0, 11],
        dtOtherSetting:{serverSide:false}
    },
    editPage:{
        editUrl:REQUEST_URL.WEB_EXECUTION_MACHINE.editMachine,
        getUrl:REQUEST_URL.WEB_EXECUTION_MACHINE.getMachine,
        rules:{
            slave_name:{
                required:true,
                minlength:2,
                maxlength:255
            },
            parallel_max: {
                required: true,
                digits: true
            },
            parallel_now: {
                required: true,
                digits: true
            },
            work_path: {
                required: true
            }
        }
    },
    templateParams:templateParams
};

$(function(){
    publish.renderParams = $.extend(true,publish.renderParams,mySetting);
    publish.init();
});
